package com.hzc.gulimall.search.thread;

import java.util.concurrent.*;

public class ThreadTest {
    public static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(10,
            50,
            10,
            TimeUnit.SECONDS,
            new LinkedBlockingDeque<>(100000),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            int i = 10 / 0;
            return i;
        }, threadPool).handle((res,exception) ->{
            if (res != null) {
                return res;
            }
            if (exception != null) {
                return 0;
            }
            return -1;
        });
        System.out.println(future.get());
    }
}
